import request from "@/utils/request.js";
import { getBlob } from "@/utils/progress";

const qs = require("qs");

// // 文件下载
// export function fileDownload(url, name) {
//   return new Promise((resolve, reject) => {
//     request({
//       url: url,
//       method: "get",
//     }).then(data => {
//       const url = window.URL.createObjectURL(new Blob([data]));
//       const link = document.createElement("a");
//       link.href = url;
//       link.setAttribute("download", name);
//       document.body.appendChild(link);
//       link.click();
//       resolve()
//     }).catch((error) => {
//       reject(error)
//     });
//   });
// }
// get请求
export function requestGet(url, params) {
  return request({ url, method: "get", params });
}
// post请求
export function requestPost(url, data) {
  return request({ url, method: "post", data: qs.stringify(data) });
}
// post请求
export function requestPost2(url, data) {
  return request({ url, method: "post", data, });
}

export function requestUrl(url, method, data) {
  if (method == 'post') return requestPost2(url, data)
  if (method == 'get') return requestGet(url, data)
}

// 下载附件
export function downloadFile(url, formDate, success, error) {
  getBlob(url, formDate, 'POST', success, error);
  // location.href = baseUrl + '/sys/attachment/download?fileUrl=' + url + '&fileName=' + name
}

